import seaborn as sns
titanic=sns.load_dataset("titanic")
titanic.head()
| survived | pclass | sex | age | sibsp | parch | fare | embarked | class | who | adult_male | deck | embark_town | alive | alone | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 3 | male | 22.0 | 1 | 0 | 7.2500 | S | Third | man | True | NaN | Southampton | no | False |
| 1 | 1 | 1 | female | 38.0 | 1 | 0 | 71.2833 | C | First | woman | False | C | Cherbourg | yes | False |
| 2 | 1 | 3 | female | 26.0 | 0 | 0 | 7.9250 | S | Third | woman | False | NaN | Southampton | yes | True |
| 3 | 1 | 1 | female | 35.0 | 1 | 0 | 53.1000 | S | First | woman | False | C | Southampton | yes | False |
| 4 | 0 | 3 | male | 35.0 | 0 | 0 | 8.0500 | S | Third | man | True | NaN | Southampton | no | True |
import plotly.express as px
import numpy as np
pip install plotly
Collecting plotly
Downloading plotly-5.13.1-py2.py3-none-any.whl (15.2 MB)
|████████████████████████████████| 15.2 MB 12.8 MB/s eta 0:00:01
Collecting tenacity>=6.2.0
Downloading tenacity-8.2.2-py3-none-any.whl (24 kB)
Installing collected packages: tenacity, plotly
Successfully installed plotly-5.13.1 tenacity-8.2.2
Note: you may need to restart the kernel to use updated packages.
px.scatter(data_frame=titanic,x="age",y="fare")
Q2. Using the tips dataset in the Plotly library, plot a box plot using Plotly express.
tips = sns.load_dataset('tips')
tips
| total_bill | tip | sex | smoker | day | time | size | |
|---|---|---|---|---|---|---|---|
| 0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
| 1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
| 2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
| 3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
| 4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 239 | 29.03 | 5.92 | Male | No | Sat | Dinner | 3 |
| 240 | 27.18 | 2.00 | Female | Yes | Sat | Dinner | 2 |
| 241 | 22.67 | 2.00 | Male | Yes | Sat | Dinner | 2 |
| 242 | 17.82 | 1.75 | Male | No | Sat | Dinner | 2 |
| 243 | 18.78 | 3.00 | Female | No | Thur | Dinner | 2 |
244 rows × 7 columns
df=px.data.tips()
fig=px.box(df,y="total_bill")
fig.show()
Q3. Using the tips dataset in the Plotly library, Plot a histogram for x= "sex" and y="total_bill" column in the tips dataset. Also, use the "smoker" column with the pattern_shape parameter and the "day" column with the color parameter.
import plotly.express as px
df=px.data.tips()
fig=px.histogram(df,x="sex",y="total_bill",color="day",pattern_shape="smoker")
fig.show()
Q4. Using the iris dataset in the Plotly library, Plot a scatter matrix plot, using the "species" column for the color parameter. Note: Use "sepal_length", "sepal_width", "petal_length", "petal_width" columns only with the dimensions parameter.
import plotly.express as px
df = px.data.iris()
fig=px.scatter_matrix(df,dimensions=["sepal_length","sepal_width","petal_length","petal_width"],
color="species")
fig.show()
Q5. What is Distplot? Using Plotly express, plot a distplot.
The displot figure factory display a combination of statistical representing of numerical data,such as histogram,kernel density estimation or normal curve,and rug plot.
The displot can composed of all or any combination of the following 3 components:- a)histogram b)curve c)rug plot
import plotly.figure_factory as ff
x=np.random.randn(1000)
hist_data=[x]
group_labels=['distplot']
fig=ff.create_distplot(hist_data,group_labels)
fig.show()